is_url <- function(path){
grepl("^https?://", path)
}
download_svg <- function(url){
filename = tempfile("inx", fileext = ".svg")
download.file(url, filename)
return(filename)
}
inx_extension <- function(input, extension, ext){
path = system('inkscape --system-data-directory', intern = TRUE)
inkscape_extensions_path = paste(path, "\\extensions", sep = "")
inkscape_python_home = paste(gsub("\\share\\inkscape", "", path, fixed = T), "\\bin", sep = "")
if(is_url(input)) {
input_file_path = download_svg(input)
} else {
input_file_path = tempfile("inx")
file.copy(input, input_file_path)
}
output = tempfile("inx", fileext = ext)
command = tempfile(pattern = "inx_", fileext = ".bat")
'@ECHO OFF
cd %s
python.exe "%s" --output="%s" "%s"' %>% sprintf(
inkscape_python_home,
paste(inkscape_extensions_path, extension, sep = "\\"),
output,
input_file_path) %>% writeLines(command)
system(command)
output
}
url <- 'https://upload.wikimedia.org/wikipedia/commons/1/1b/Red_Bird.svg'
#browseURL(url)
knitr::include_graphics(url)

logo <- inx_extension(input = url, extension = "dxf12_outlines.py", ext =".dxf") %>%
st_read() %>%
select(geometry) %>% st_union() %>% st_polygonize() %>%
first()
## Reading layer `entities' from data source
## `C:\Users\jacek\AppData\Local\Temp\Rtmp4CvSV5\inx1484238c6351.dxf'
## using driver `DXF'
## Simple feature collection with 8654 features and 6 fields
## Geometry type: LINESTRING
## Dimension: XY
## Bounding box: xmin: 238.9009 ymin: -837.4039 xmax: 1105.521 ymax: 40.07607
## CRS: NA
logo %>% ggplot() +
geom_sf()

result <- st_sfc() %>% st_sf(geometry = .)
for(i in c(1: length(logo))) {
tmp <- logo %>%
nth(i) %>%
st_sfc() %>% st_sf(geometry = .) %>% mutate(facet = i)
result <- tmp %>% bind_rows(result)
}
result %>% plot_ly(split = ~facet)
## No trace type specified:
## Based on info supplied, a 'scatter' trace seems appropriate.
## Read more about this trace type -> https://plotly.com/r/reference/#scatter
logo <- result %>% filter(!facet %in% c(5, 50:52, 56:60))
logo %>% ggplot() +
geom_sf() +
theme_void()
